package CXFCallTest;

import com.czmh.etc.interpreter.Utils.CXFUtils;
import com.czmh.etc.interpreter.Utils.StringUtils;
import com.czmh.etc.interpreter.entity.base.EnMessagetype;
import com.czmh.etc.interpreter.entity.base.InterpreterContent;
import com.czmh.etc.interpreter.entity.request.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang.time.DateFormatUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by Huangyk on 2019/6/6.
 */
public class testMain {
    public static String url = "http://192.168.157.132:9090/mex?wsdl";
    public static String methodName = "Request";

    public static void registorUserInfo(){
        try {
            CardUserInfoOperateRequest request = new CardUserInfoOperateRequest();

            request.setMsgLen(CardUserInfoOperateRequest.MSG_LEN);
            request.setMsgType(EnMessagetype.CardUserInfoOperateRequest);
            request.setSenderOrgCode(InterpreterContent.SENDER_ORG_CODE);
            request.setRecvOrgCode(InterpreterContent.RECV_ORG_CODE);
            String sendTimeStr = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
            request.setSendTime(sendTimeStr);
            request.setVerifyCode(new Long("2518611137"));

            request.setWasteSn("90" + sendTimeStr + "0713");
            request.setPosID("8000000");
            request.setTerminalID("  100000000001");
            request.setGenTime(sendTimeStr);
            request.setOptType("1");
            request.setUserType("0");
            request.setUserName(StringUtils.rightPadByByteLen(InterpreterContent.USER_NAME, 60, ' '));
            request.setCertType(InterpreterContent.USER_CERT_TYPE);
            request.setCertSN(StringUtils.rightPadByByteLen(InterpreterContent.USER_CERT_SN, 32, ' '));
            request.setLinkAddr(StringUtils.rightPadByByteLen("女难道你大佛你那送到裂缝的女奥念佛按地方", 100, ' '));
            request.setDepartment(StringUtils.rightPadByByteLen("", 100, ' '));
            request.setRegisteredType("1");
            request.setAgentName(StringUtils.rightPadByByteLen("", 150, ' '));
            request.setAgentIdType(StringUtils.rightPadByByteLen("", 2, ' '));
            request.setAgentIdNum(StringUtils.rightPadByByteLen("", 30, ' '));
            request.setTel(StringUtils.rightPadByByteLen("", 20, ' '));
            request.setBank(StringUtils.rightPadByByteLen("", 300, ' '));
            request.setBankAddr(StringUtils.rightPadByByteLen("", 300, ' '));
            request.setBankAccount(StringUtils.rightPadByByteLen("", 20, ' '));
            request.setTaxpayerCode(StringUtils.rightPadByByteLen("", 20, ' '));

            List<Object> params = new ArrayList<Object>();

            ObjectMapper mapper = new ObjectMapper();
            String jsonStr = mapper.writeValueAsString(request);

            params.add(EnMessagetype.CardUserInfoOperateRequest.getMessageType());
            params.add(jsonStr);

            Object[] result = CXFUtils.Call(testMain.url, "Request", params);

            for(Object obj : result){
                System.out.println("------------------------------------------------------------------------------");
                System.out.println("" + obj);
                System.out.println("------------------------------------------------------------------------------");
            }
        }catch (Exception exp){
            exp.printStackTrace();
        }

    }

    public static void checkCardInfoRequest(){
        try {
            CardInfoRequest request = new CardInfoRequest();
            //00000168910791000006300000201606140839026D97DB8B912016061408390215999101001100000000001  630100000000100543402630102197904070042              000000610020160614083902

            request.setMsgLen(CardUserInfoOperateRequest.MSG_LEN);
            request.setMsgType(EnMessagetype.CardUserInfoOperateRequest);
            request.setSenderOrgCode(InterpreterContent.SENDER_ORG_CODE);
            request.setRecvOrgCode(InterpreterContent.RECV_ORG_CODE);
            String sendTimeStr = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
            request.setSendTime(sendTimeStr);
            request.setVerifyCode(new Long("1838668683"));

            request.setWasteSn("91" + sendTimeStr + "1599");
            //request.setWasteSn("80" + sendTimeStr + "0713");
            request.setPosID("9101001");
            request.setTerminalID("100000000001  ");
            //request.setCardNo("63010000000010054340");
            request.setCardNo("63011824220101001983");
            request.setCertType("02");
            request.setCertSN("630102197904070042              ");
            request.setCardStoreMoney(new Long("0000006100"));
            request.setQueryTime(sendTimeStr);

            List<Object> params = new ArrayList<Object>();

            ObjectMapper mapper = new ObjectMapper();
            String jsonStr = mapper.writeValueAsString(request);

            params.add(EnMessagetype.CardInfoRequest.getMessageType());
            params.add(jsonStr);

            Object[] result = CXFUtils.Call(testMain.url, "Request", params);

            for(Object obj : result){
                System.out.println("------------------------------------------------------------------------------");
                System.out.println("" + obj);
                System.out.println("------------------------------------------------------------------------------");
            }
        }catch (Exception exp){
            exp.printStackTrace();
        }
    }

    public static void searchConsumeDetailRequest(){
        try {
/*

            request.MsgLen = 00000160;
            request.MsgID = 91;
            request.MsgType = EnMessagetype.ConsumeDetailRequest;
            request.SenderOrgCode = "9000000";
            request.RecvOrgCode = "6300000";
            request.SendTime = "20160614090213";
            request.VerifyCode = ulong.Parse("08F525FD", System.Globalization.NumberStyles.HexNumber);

            request.WasteSn = "90201606140902132448";
            request.PosID = "9063176";
            request.TerminalID = "900000000000  ";

            request.GenTime = "20160614090213";
            request.CardNo = "63011504220203064573";
            request.CardType = 22;
            request.Starttime = "20160501      ";
            request.Endtime = "20160531      ";
*/
            ConsumeDetailRequest request = new ConsumeDetailRequest();
            request.setMsgLen(ConsumeDetailRequest.MSG_LEN);
            request.setMsgType(EnMessagetype.ConsumeDetailRequest);
            request.setSenderOrgCode("9000000");
            request.setRecvOrgCode("6300000");
            String sendTimeStr = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
            request.setSendTime(sendTimeStr);
            request.setVerifyCode(new Long("1838668683"));
//            request.setVerifyCode(new Long("150283773"));

            request.setWasteSn("90" + sendTimeStr + "2448");
            request.setPosID("9063176");
            request.setTerminalID("900000000000  ");

            request.setGenTime(sendTimeStr);
            request.setCardNo("63011824220101001983");
            request.setCardType("22");
            request.setStarttime("20100501      ");
            request.setEndtime("20180531      ");

            List<Object> params = new ArrayList<Object>();

            ObjectMapper mapper = new ObjectMapper();
            String jsonStr = mapper.writeValueAsString(request);

            params.add(EnMessagetype.ConsumeDetailRequest.getMessageType());
            params.add(jsonStr);

            Object[] result = CXFUtils.Call(testMain.url, "Request", params);

            for(Object obj : result){
                System.out.println("------------------------------------------------------------------------------");
                System.out.println("" + obj);
                System.out.println("------------------------------------------------------------------------------");
            }

        }catch (Exception exp){
            exp.printStackTrace();
        }
    }

    public static void registorCarInfo(){
        try {
            CardCarInfoOperateRequest request = new CardCarInfoOperateRequest();

            request.setMsgLen(ConsumeDetailRequest.MSG_LEN);
            request.setMsgType(EnMessagetype.ConsumeDetailRequest);
            request.setSenderOrgCode("9000000");
            request.setRecvOrgCode("6300000");
            String sendTimeStr = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
            request.setSendTime(sendTimeStr);
            request.setVerifyCode(new Long("1838668683"));

            //流水号 20
            request.setWasteSn("90" + sendTimeStr + "2448");
            //网点编号 7
            request.setPosID("9063176");
            //终端机编号
            request.setTerminalID(StringUtils.rightPadByByteLen("6300204", 14, ' '));

            //申请时间  14
            request.setGenTime(sendTimeStr);
            //操作类型 1
            request.setOptType("1");
            //车牌号 14
            request.setVLP(StringUtils.rightPadByByteLen("青A23654", 14, ' '));
            //车牌底色 1
            request.setVLPC("0");
            //收费车型 2
            request.setVClass("01");
            //机动车所有人 50
            request.setOwnerName(StringUtils.rightPadByByteLen("测试车主", 50, ' '));
            //所有人证件类型 2
            request.setOwnerIdType("02");
            //所有人证件号
            request.setOwnerIdNum(StringUtils.rightPadByByteLen("604145874232116518", 30, ' '));
            //用户类型 1
            request.setUserType("0");
            //注册用户证件类型 2
            request.setCertType("02");
            //注册用户证件号 30
            request.setCertSN(StringUtils.rightPadByByteLen("604145874232116518", 30, ' '));
            //录入方式 1
            request.setRegisteredType("1");
            //所有人联系电话    20
            request.setOwnerTel(StringUtils.rightPadByByteLen("15323318861", 20, ' '));
            //联系地址      100
            request.setAddress(StringUtils.rightPadByByteLen("测试机动车所有人联系地址", 100, ' '));
            //联系人姓名    50
            request.setContact(StringUtils.rightPadByByteLen("联系人", 50, ' '));
            //车辆类型      50
            request.setVehicleType(StringUtils.rightPadByByteLen("行驶证内容bala bala", 50, ' '));
            //行驶证品牌型号  50
            request.setVehicleMode(StringUtils.rightPadByByteLen("行驶证内容，行驶证品牌型号", 50, ' '));
            //车辆使用性质   4
            request.setUseCharacter(StringUtils.leftPadByByteLen("2", 4, '0'));
            //车辆识别代号   50
            request.setVIN(StringUtils.rightPadByByteLen("车辆识别代号，行驶证内容", 50, ' '));
            //车辆发动机号    50
            request.setEngineNum(StringUtils.rightPadByByteLen("E1561561", 50, ' '));
            //注册日期    20
            request.setRegisterDate(StringUtils.rightPadByByteLen("20111120", 20, ' '));
            //发证日期   20
            request.setIssueDate(StringUtils.rightPadByByteLen("20111120", 20, ' '));
            //档案编号   50
            request.setFileNum(StringUtils.rightPadByByteLen("51asd65f1a6s5d1f", 50, ' '));
            //定载人数   4
            request.setApprovedCount(StringUtils.leftPadByByteLen("7", 4, '0'));
            //总质量    10
            request.setTotalMass(StringUtils.leftPadByByteLen("1500", 10, '0'));
            //整备质量   10
            request.setMaintenanceMass(StringUtils.leftPadByByteLen("1500", 10, '0'));
            //核定载质量  10
            request.setPermittedWeight(StringUtils.leftPadByByteLen("1500", 10, '0'));
            //外廓尺寸   100
            request.setOutsideDimensions(StringUtils.rightPadByByteLen("1500×1500×1300", 100, '0'));
            //牵引总质量  10
            request.setPermittedToWeight(StringUtils.leftPadByByteLen("1500", 10, '0'));
            //检验记录    50
            request.setTestRecord(StringUtils.rightPadByByteLen("testrecords", 50, ' '));
            //车路数   4
            request.setWheelCount(StringUtils.leftPadByByteLen("4", 4, '0'));
            //车轴数   4
            request.setAxleCount(StringUtils.leftPadByByteLen("2", 4, '0'));
            //轴距    10
            request.setAxleDistance(StringUtils.leftPadByByteLen("1500", 10, '0'));
            //轴型    50
            request.setAxisType(StringUtils.rightPadByByteLen("轴型dlknfadnb", 50, ' '));

            List<Object> params = new ArrayList<Object>();

            ObjectMapper mapper = new ObjectMapper();
            String jsonStr = mapper.writeValueAsString(request);

            params.add(EnMessagetype.CardCarInfoOperateRequest.getMessageType());
            params.add(jsonStr);

            Object[] result = CXFUtils.Call(testMain.url, "Request", params);

            for(Object obj : result){
                System.out.println("------------------------------------------------------------------------------");
                System.out.println("" + obj);
                System.out.println("------------------------------------------------------------------------------");
            }

        }catch (Exception exp){
            exp.printStackTrace();
        }
    }

    public static void checkCardInfoChangeRequest(){
        try {
            CardInfoChangeRequest request = new CardInfoChangeRequest();

            request.setMsgLen(CardInfoChangeRequest.MSG_LEN);
            request.setMsgType(EnMessagetype.CardInfoChangeRequest);
            request.setSenderOrgCode(InterpreterContent.SENDER_ORG_CODE);
            request.setRecvOrgCode(InterpreterContent.RECV_ORG_CODE);
            String sendTimeStr = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
            request.setSendTime(sendTimeStr);
            request.setVerifyCode(new Long("1838668683"));
            //63011824220101001983

            request.setWasteSn("90" + sendTimeStr + "0025");
            request.setPosID("9101001");
            request.setTerminalID("100000000001  ");
            request.setGenTime(sendTimeStr);
            request.setOptType('1');
            request.setFileType('1');
            request.setBankID("9101001");
            request.setAccountID("1656159619618964184");
            request.setCardType("22");
            request.setAccType("232");
            request.setTransType('1');
            request.setTransferLimit(new BigDecimal(10000));
            request.setTallyLimit(new BigDecimal(1000));
            request.setCardID("63011824220101001983");
            request.setUserType('0');
            request.setUserName(StringUtils.rightPadByByteLen("用户名", 60, ' '));
            request.setCertType("02");
            request.setCertSN(StringUtils.rightPadByByteLen("156165196816896419", 32, ' '));
            request.setCardCost(30);
            request.setLinkAddr(StringUtils.rightPadByByteLen("联系地址", 100, ' '));
            request.setLinkPost("000000");
            request.setLinkTel(StringUtils.rightPadByByteLen("15323318861", 16, ' '));
            request.setLinkMobile(StringUtils.rightPadByByteLen("15323318861", 16, ' '));
            request.setLinkFax(StringUtils.rightPadByByteLen("", 16, ' '));
            request.setLinkMail(StringUtils.rightPadByByteLen("", 60, ' '));
            request.setVLPC('0');
            request.setVLP(StringUtils.rightPadByByteLen("青A16516", 14, ' '));
            request.setVclass("02");
            request.setRandom(StringUtils.leftPadByByteLen("23", 8, '0'));
            request.setCardVer("40");
            request.setBrand("02");
            request.setIssuedType('1');
            request.setModel("16531561965168516541");

            List<Object> params = new ArrayList<Object>();

            ObjectMapper mapper = new ObjectMapper();
            String jsonStr = mapper.writeValueAsString(request);

            params.add(EnMessagetype.CardInfoChangeRequest.getMessageType());
            params.add(jsonStr);

            Object[] result = CXFUtils.Call(testMain.url, "Request", params);

            for(Object obj : result){
                System.out.println("------------------------------------------------------------------------------");
                System.out.println("" + obj);
                System.out.println("------------------------------------------------------------------------------");
            }
        }catch (Exception exp){
            exp.printStackTrace();
        }
    }

    public static void operCardDelayRequest(){
        try {

        }catch (Exception exp){
            exp.printStackTrace();
        }
    }

    public static void main(String[] args){
        //registorUserInfo();

        //checkCardInfoRequest();

        //searchConsumeDetailRequest();

        //registorCarInfo();

        //checkCardInfoChangeRequest();


    }
}
